/**
 * 便捷的上传方法
 */

import uploadConfig from "../../config/upload";
import formatDate from "../../utils/common";
import serverUpload from "./server";
import ossUpload from "./oss";
import qiniuUpload from "./qiniu";
import bosUpload from "./bos";
import cosUpload from "./cos";

export function doUpload( file, config) {
    let type = uploadConfig.editor_upload_type;
    let fun = null;

    let failure = config.failure;
    config.failure = ( e)=>{
        console.error( "上传失败", e);
        failure && failure( e);
    }

    switch( type){
        case "server":
            fun = serverUpload;
            break;
        case "oss":
            fun = ossUpload;
            break;
        case "qiniu":
            fun = qiniuUpload;
            break;
        case "bos":
            fun = bosUpload;
            break;
        case "cos":
            fun = cosUpload;
            break;
    }

    fun && fun( file, config);
}

